package cn.hr.base;

import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

/**
 * 服务层父接口
 *
 * @param <T>
 * @author MO
 */
public interface BaseService<T> {
    /**
     * 新增
     *
     * @param t
     * @return
     * @throws Exception
     */
    @Transactional
    @CacheEvict(allEntries = true)
    boolean insert(T t) throws Exception;

    /**
     * 根据id修改
     *
     * @param t
     * @return
     * @throws Exception
     */
    @Transactional
    @CacheEvict(allEntries = true)
    boolean update(T t) throws Exception;

    /**
     * 根据id删除
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Transactional
    @CacheEvict(allEntries = true)
    boolean delete(Integer id) throws Exception;

    /**
     * 根据id获取对象
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Cacheable(keyGenerator = "keyGenerator")
    T get(Integer id) throws Exception;

    /**
     * 根据查询条件分页查询
     *
     * @param m 查询条件
     * @throws Exception
     */
    //@Cacheable(keyGenerator = "keyGenerator")
    PageInfo<Map> findListByCondition(Map m, int pageNo) throws Exception;

    /**
     * 根据查询条件查询总记录数
     *
     * @param m 查询条件
     * @return
     */
    @Cacheable(keyGenerator = "keyGenerator")
    Long findCountByCondition(Map m) throws Exception;
}
